# Learn Double Examples Sub-project
# Note: This is a sub-project of cpp_learn_template_srsj
# C++ standard and build type are inherited from parent project

message(STATUS "Configuring learn_double examples...")

# 定义所有的源文件（每个都有 main 函数）
set(SOURCES
    check_0075_save_more.cpp
    comp_6d80_0_75.cpp
    cpp_0075_chen100.cpp
    display_0_075_dec.cpp
    display_0_075_hex.cpp
    get_008_from_0075.cpp
    outputCfenvMode.cpp
    preciseToFixed_likeJs.cpp
    to_0-075.cpp
    to_6d80.cpp
)

# 为每个源文件创建一个可执行文件
foreach(source ${SOURCES})
    # 获取文件名（不包含扩展名）作为目标名
    get_filename_component(target_name ${source} NAME_WE)
    
    # 创建可执行目标
    add_executable(${target_name} ${source})
    
    # 设置输出目录到项目根目录的 build/bin/learn_double/
    set_target_properties(${target_name} PROPERTIES
        RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/learn_double
    )
    
    message(STATUS "Added executable: ${target_name} from ${source}")
endforeach()

# 添加 'all_examples' 目标，用于一次性构建所有示例
add_custom_target(all_examples)

foreach(source ${SOURCES})
    get_filename_component(target_name ${source} NAME_WE)
    add_dependencies(all_examples ${target_name})
endforeach()

# 添加清理目标
add_custom_target(clean_examples
    COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_BINARY_DIR}/bin
    COMMENT "Cleaning example executables"
)

# 输出信息
message(STATUS "=== Learn Double Examples Project ===")
message(STATUS "Available targets:")
foreach(source ${SOURCES})
    get_filename_component(target_name ${source} NAME_WE)
    message(STATUS "  - ${target_name}")
endforeach()
message(STATUS "Special targets:")
message(STATUS "  - all_examples: Build all examples")
message(STATUS "  - clean_examples: Clean executable files")
message(STATUS "=====================================")
